/*
* JoglRenderer.java
* Copyright (C) 2003
*
* $Id: JoglRenderer.java,v 1.6 2004/12/14 00:11:03 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
using Defines = Suake2.UI.Defines;
using refdef_t = Suake2.UI.client.refdef_t;
using refexport_t = Suake2.UI.client.refexport_t;
using xcommand_t = Suake2.UI.qcommon.xcommand_t;
using Misc = Suake2.UI.render.jogl.Misc;
using JOGLKBD = Suake2.UI.sys.JOGLKBD;
using KBD = Suake2.UI.sys.KBD;
namespace Suake2.UI.render
{
	
	/// <summary> JoglRenderer
	/// 
	/// </summary>
	/// <author>  cwei
	/// </author>
	sealed class JoglRenderer:Misc, refexport_t, Ref
	{
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t5' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t5:xcommand_t
		{
			public AnonymousClassxcommand_t5(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.R_BeginRegistration(Enclosing_Instance.name);
			}
		}
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t6' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t6:xcommand_t
		{
			public AnonymousClassxcommand_t6(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.model = Enclosing_Instance.R_RegisterModel(Enclosing_Instance.name);
			}
		}
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t7' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t7:xcommand_t
		{
			public AnonymousClassxcommand_t7(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.image = Enclosing_Instance.R_RegisterSkin(Enclosing_Instance.name);
			}
		}
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t8' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t8:xcommand_t
		{
			public AnonymousClassxcommand_t8(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.image = Enclosing_Instance.Draw_FindPic(Enclosing_Instance.name);
			}
		}
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t9' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t9:xcommand_t
		{
			public AnonymousClassxcommand_t9(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.R_SetSky(Enclosing_Instance.name, Enclosing_Instance.rotate, Enclosing_Instance.axis);
			}
		}
		//UPGRADE_NOTE: Field 'EnclosingInstance' was added to class 'AnonymousClassxcommand_t10' to access its enclosing instance. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1019'"
		private class AnonymousClassxcommand_t10:xcommand_t
		{
			public AnonymousClassxcommand_t10(JoglRenderer enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
			private void  InitBlock(JoglRenderer enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
			private JoglRenderer enclosingInstance;
			public JoglRenderer Enclosing_Instance
			{
				get
				{
					return enclosingInstance;
				}
				
			}
			public override void  execute()
			{
				Enclosing_Instance.R_EndRegistration();
			}
		}
		public System.String Name
		{
			// ============================================================================
			// Ref interface
			// ============================================================================
			
			
			get
			{
				return DRIVER_NAME;
			}
			
		}
		public KBD KeyboardHandler
		{
			get
			{
				return kbd;
			}
			
		}
		
		private JOGLKBD kbd = new JOGLKBD();
		
		public const System.String DRIVER_NAME = "jogl";
		
		
		private JoglRenderer()
		{
		}
		
		// ============================================================================
		// public interface for Renderer implementations
		//
		// refexport_t (ref.h)
		// ============================================================================
		
		/// <seealso cref="jake2.client.refexport_t.Init()">
		/// </seealso>
		public bool Init(int vid_xpos, int vid_ypos)
		{
			// pre init
			if (!R_Init(vid_xpos, vid_ypos))
				return false;
			// calls the R_Init2() internally		
			updateScreen();
			// the result from R_Init2()
			return post_init;
		}
		
		/// <seealso cref="jake2.client.refexport_t.Shutdown()">
		/// </seealso>
		public void  Shutdown()
		{
			R_Shutdown();
		}
		
		/// <seealso cref="jake2.client.refexport_t.BeginRegistration(java.lang.String)">
		/// </seealso>
		public void  BeginRegistration(System.String map)
		{
			if (contextInUse)
			{
				R_BeginRegistration(map);
				return ;
			}
			
			this.name = map;
			
			updateScreen(new AnonymousClassxcommand_t5(this));
		}
		
		
		private model_t model = null;
		private System.String name = null;
		
		/// <seealso cref="jake2.client.refexport_t.RegisterModel(java.lang.String)">
		/// </seealso>
		public model_t RegisterModel(System.String name)
		{
			
			if (contextInUse)
				return R_RegisterModel(name);
			
			model = null;
			this.name = name;
			
			updateScreen(new AnonymousClassxcommand_t6(this));
			return model;
		}
		
		/// <seealso cref="jake2.client.refexport_t.RegisterSkin(java.lang.String)">
		/// </seealso>
		public image_t RegisterSkin(System.String name)
		{
			if (contextInUse)
				return R_RegisterSkin(name);
			
			this.image = null;
			this.name = name;
			
			updateScreen(new AnonymousClassxcommand_t7(this));
			return image;
		}
		
		private image_t image = null;
		
		/// <seealso cref="jake2.client.refexport_t.RegisterPic(java.lang.String)">
		/// </seealso>
		public image_t RegisterPic(System.String name)
		{
			if (contextInUse)
				return Draw_FindPic(name);
			
			this.image = null;
			this.name = name;
			
			updateScreen(new AnonymousClassxcommand_t8(this));
			return image;
		}
		
		private float[] axis;
		private float rotate;
		
		/// <seealso cref="jake2.client.refexport_t.SetSky(java.lang.String, float, float[])">
		/// </seealso>
		public void  SetSky(System.String name, float rotate, float[] axis)
		{
			if (contextInUse)
			{
				R_SetSky(name, rotate, axis);
				return ;
			}
			
			this.name = name;
			this.rotate = rotate;
			this.axis = axis;
			
			updateScreen(new AnonymousClassxcommand_t9(this));
		}
		
		/// <seealso cref="jake2.client.refexport_t.EndRegistration()">
		/// </seealso>
		public void  EndRegistration()
		{
			if (contextInUse)
			{
				R_EndRegistration();
				return ;
			}
			
			updateScreen(new AnonymousClassxcommand_t10(this));
		}
		
		/// <seealso cref="jake2.client.refexport_t.RenderFrame(jake2.client.refdef_t)">
		/// </seealso>
		public void  RenderFrame(refdef_t fd)
		{
			R_RenderFrame(fd);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawGetPicSize(java.awt.Dimension, java.lang.String)">
		/// </seealso>
		//UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
		public void  DrawGetPicSize(ref System.Drawing.Size dim, System.String name)
		{
			//UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
			Draw_GetPicSize(ref dim, name);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawPic(int, int, java.lang.String)">
		/// </seealso>
		public void  DrawPic(int x, int y, System.String name)
		{
			Draw_Pic(x, y, name);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawStretchPic(int, int, int, int, java.lang.String)">
		/// </seealso>
		public void  DrawStretchPic(int x, int y, int w, int h, System.String name)
		{
			Draw_StretchPic(x, y, w, h, name);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawChar(int, int, int)">
		/// </seealso>
		public void  DrawChar(int x, int y, int num)
		{
			Draw_Char(x, y, num);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawTileClear(int, int, int, int, java.lang.String)">
		/// </seealso>
		public void  DrawTileClear(int x, int y, int w, int h, System.String name)
		{
			Draw_TileClear(x, y, w, h, name);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawFill(int, int, int, int, int)">
		/// </seealso>
		public void  DrawFill(int x, int y, int w, int h, int c)
		{
			Draw_Fill(x, y, w, h, c);
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawFadeScreen()">
		/// </seealso>
		public void  DrawFadeScreen()
		{
			Draw_FadeScreen();
		}
		
		/// <seealso cref="jake2.client.refexport_t.DrawStretchRaw(int, int, int, int, int, int, byte[])">
		/// </seealso>
		public void  DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, sbyte[] data)
		{
			Draw_StretchRaw(x, y, w, h, cols, rows, data);
		}
		
		/// <seealso cref="jake2.client.refexport_t.CinematicSetPalette(byte[])">
		/// </seealso>
		public void  CinematicSetPalette(sbyte[] palette)
		{
			R_SetPalette(palette);
		}
		
		/// <seealso cref="jake2.client.refexport_t.BeginFrame(float)">
		/// </seealso>
		public void  BeginFrame(float camera_separation)
		{
			R_BeginFrame(camera_separation);
		}
		
		/// <seealso cref="jake2.client.refexport_t.EndFrame()">
		/// </seealso>
		public void  EndFrame()
		{
			GLimp_EndFrame();
		}
		
		/// <seealso cref="jake2.client.refexport_t.AppActivate(boolean)">
		/// </seealso>
		public void  AppActivate(bool activate)
		{
			GLimp_AppActivate(activate);
		}
		
		public int apiVersion()
		{
			return Defines.API_VERSION;
		}
		
		public override System.String ToString()
		{
			return DRIVER_NAME;
		}
		
		public refexport_t GetRefAPI()
		{
			return this;
		}
		static JoglRenderer()
		{
			{
				Renderer.register(new JoglRenderer());
			}
		}
	}
}